package com.ringtheweb.model.notification;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.MapKey;
import org.hibernate.annotations.Type;

/**
 * A notification
 * @author Luc
 *
 */
@Entity
@Table(name="NOTIFICATION")
@DiscriminatorColumn(name="TYPE")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class Notification implements Serializable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	
	@Column(name="STATUS")
	private boolean status;
	
	@CollectionOfElements
	@JoinTable(
			name="NOTIFICATION_HISTORY",
			joinColumns=@JoinColumn(name="NOTIFICATION_ID"))
	@MapKey(columns=@Column(name="DATE"))
	@Column(name="MESSAGE",length=5000)
	//@Type(type="text") does not work see defect http://opensource.atlassian.com/projects/hibernate/browse/ANN-696
	@Fetch(FetchMode.JOIN)
	@Cascade(CascadeType.ALL)
	private Map<Date,String> historyLines = new TreeMap<Date,String>();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public Map<Date, String> getHistoryLines() {
		return historyLines;
	}

	public void setHistoryLines(Map<Date, String> historyLines) {
		this.historyLines = historyLines;
	}
	

	
	
	

}
